package com.example.adms.role.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.example.adms.role.service.RoleService;
import com.example.adms.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 获取用户权限列表
     * @param token
     * @return
     */
    @GetMapping("/roleList")
    public Result getRoleList(@RequestHeader("Authorization") String token){
        boolean login = StpUtil.isLogin();
        return roleService.getRoleListById(token);
    }

    /**
     * 通过用户id获取对应角色
     * @param token
     * @return
     */
    @GetMapping("/getRoleById")
    public Result getRoleById(@RequestHeader("Authorization") String token){
        return roleService.getRoleById(token);
    }

    /**
     * 获取所有角色
     * @return
     */
    @GetMapping("/getRoleList")
    public Result getRoleList(){
        return roleService.getRoleList();
    }
}
